package org.aphelie.chronicle.viewer;

import org.aphelie.chronicle.ChroniclePackage;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EStructuralFeature.Setting;
import org.eclipse.emf.ecp.view.model.common.ECPRendererTester;
import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
import org.eclipse.emf.ecp.view.spi.model.VControl;
import org.eclipse.emf.ecp.view.spi.model.VElement;

public class ArcTupleControlRendererTest implements ECPRendererTester {
	
	private static final int PRIORITY = 0;

	@Override
	public int isApplicable(VElement vElement, ViewModelContext context) {
		if (VControl.class.isInstance(vElement)) {
			EStructuralFeature s = VControl.class.cast(vElement).getDomainModelReference().getEStructuralFeatureIterator().next();
			Setting x =VControl.class.cast(vElement).getDomainModelReference().getIterator().next();
			
			//Setting f = VControl.class.cast(vElement).getDomainModelReference().getIterator().next();
			//return isApplicableForObject(f.getEObject(), vElement, context);
			return isApplicableForFeature(s, vElement, context);
		}
		return NOT_APPLICABLE;
	}
	
	public void display(Object... args) {
		String message = "";
		for (int i = 0; i < args.length; ++i) {
			if (i > 0) {
				message += " # ";
			}
			message += args[i];
		}
		System.err.println(message);
	}
	
	public int isApplicableForObject(EObject object, VElement vElement, ViewModelContext context) {

		boolean test = ChroniclePackage.eINSTANCE.getArcTuple().isSuperTypeOf(object.eClass());
		display(test, object.eClass(), ChroniclePackage.eINSTANCE.getArcTuple());
		display(test);
		if (test) {
			return PRIORITY;
		}
		return NOT_APPLICABLE;
	}
	
    public int isApplicableForFeature(EStructuralFeature feature, VElement vElement, ViewModelContext context) {
    	boolean apply = feature.equals(ChroniclePackage.eINSTANCE.getArcTuple_Scores());
    	display(apply, feature.eClass());
    	
        if (apply) {
            return 10;
        }
        return NOT_APPLICABLE;
    }

}
